home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / PCCDEMO.ZIP / COMP1.EXE / WATSPEED.PRS < prev    next >
Text File  |  1993-12-20  |  7KB  |  155 lines

  1.                                                    ûçÇô ÆÅääâ? ╬╠╬╠╬╠╬╠╬╠╧╧╡
  2.  
  3.  
  4.        îα±Γ â⌠σε⌠±.
  5.  
  6.  
  7. ôτΣ≥Σ πα√≥, ÷Φ≤τ ≤τΣ ΦφσΦφΦ≤Σδ√ ⌡α±√Φφµ ∩ε÷Σ± εσ ≤επα√'≥ Γε∞∩⌠≤Σ±≥, Φ≤ Φ≥ 
  8. ≥ε∞Σ≤Φ∞Σ≥ α ΓταδδΣφµΣ ≤ε πΣ≥Φµφ α ⌠≥Σ± Φφ≤Σ±σαΓΣ ≤τα≤ ÷Φδδ ßΣ ≥∩ΣΣπΦδ√ 
  9. Γεφ≥Φ≥≤Σφ≤ σ±ε∞ Γε∞∩⌠≤Σ± ≤ε Γε∞∩⌠≤Σ±. The fastest micro-processors will 
  10. execute the same instructions more than 150 times faster than the slowest 
  11. chips available, thus adding slightly to the challenge of producing software 
  12. that will perform consistently from one machine to the other.
  13.  
  14.    ôτΣ ∞Σ≤τεπ ±Σ≤αΦφΣπ Φφ⌡εδ⌡Σ≥ ≤τΣ ⌠≥Σ εσ α  "≥∩ΣΣπ ΦφπΣ≈", 
  15.    that is  proportional to  the speed of the microprocessor 
  16.    executing the code below. 
  17.       The higher the number,  the  faster  the chip is. This 
  18.    number  is  simply  obtained  by  counting  the number of 
  19.    iterations of a particular  "representative code" routine 
  20.    during a fixed  time  interval  obtained  by the system's 
  21.    real-time clock. The "representative code" is intended to 
  22.    be either representative  of  the kind of computation the 
  23.    program is intended to perform, or sufficiently varied in 
  24.    order to "fool"  some  of the  more performing processors 
  25.    that gain their speed using  sophisticated caching and/or 
  26.    pipelining processes. In the example given below, we move 
  27.    data  between  two  arbitrarily  large  arrays,  that are 
  28.    allocated  and  de-allocated  during  each  call  of  the 
  29.    "representative code" routine. Furthermore, the direction 
  30.    of the data  movement is  dependent of  a  random  value; 
  31.    however, you  will  notice that  the  alternate execution 
  32.    paths are strictly equivalent, so to be able to cope with 
  33.    any eventual random number generator bias.
  34.    
  35.    ôτΦ≥ ±ε⌠≤ΦφΣ Φ≥ Φφ≤ΣφπΣπ ≤ε ßΣ ⌠≥Σπ ß√ αφ√εφΣ Φφ αφ√ δαφµ⌠αµΣ; 
  36.    the example given below is given in Borland Turbo Pascal 6.0, 
  37.    but can be easily adapted and translated into any other popular 
  38.    language. 
  39.  
  40.    ôτΣ ΓεπΣ ßΣδε÷ Φ≥ ΦφΓδ⌠πΣπ Φφ ≤τΣ σΦδΣ ôêîä.ÅÇÆ
  41.  
  42.  
  43.  (*****************************************************************)
  44.  (*     TIME unit - for the determination of true system speed.   *)
  45.  (*                                                               *)
  46.  (*  This unit returns a value proportional to the speed of the   *)
  47.  (*  CPU of the computer it is running on.                        *)
  48.  (*                                                               *)
  49.  (*  Written in Borland Turbo Pascal version 6.0                  *)
  50.  (*                          By Marc Dufour, September 18, 1993   *)
  51.  (*****************************************************************)
  52.  
  53.  unit time;
  54.  
  55.  interface
  56.  
  57.  function speed_index: longint;
  58.  
  59.  (*****************************************************************)
  60.  (* That's it. One tiny function that returns the value gathered  *)
  61.  (* during the unit's initialization (automatically called when   *)
  62.  (* the "time" unit is referenced for the first time.             *)
  63.  (*    Oh, what? Why a function? Well, it's to keep the unit as   *)
  64.  (* it should be, a one-way provider of information, so to insure *)
  65.  (* that the value is not clobbered by careless programming, and  *)
  66.  (* to adhere to the canons of clean, simple and structured       *)
  67.  (* programming.                                                  *)
  68.  (*****************************************************************)
  69.  
  70.  implementation
  71.  uses dos;
  72.  
  73.  var TimeCount: longint;
  74.  
  75.  (*****************************************************************)
  76.  (* This is the function that is called to gain acces to the      *)
  77.  (* variable "TimeCount", that is kept securely within the body   *)
  78.  (* of the "time" unit to insure it's strict output-only role.    *)
  79.  (*****************************************************************)
  80.  function speed_index: longint;
  81.  begin
  82.  speed_index:=TimeCount;
  83.  end; {speed_index}
  84.  
  85.  (*****************************************************************)
  86.  (* This function returns the number of seconds since midnight.   *)
  87.  (*****************************************************************)
  88.  function time_of_day: longint;
  89.  var Hour,
  90.      Minute,
  91.      Second,
  92.      Sec100: Word;
  93.  begin
  94.  dos.GetTime(Hour, Minute, Second, Sec100);
  95.  time_of_day:=hour*3600+minute*60+second;
  96.  end; {time_of_day}
  97.  
  98.  (*****************************************************************)
  99.  (* This procedure emulates the kind of processing the system is  *)
  100.  (* supposed to perform during the execution of the program. Some *)
  101.  (* fast processors optimize the code that is executed or the     *)
  102.  (* position of the data, so we try to be as generous as possible *)
  103.  (* in generating differing processing possibilites, as to insure *)
  104.  (* that the calculations done reflect as accurately as possible  *)
  105.  (* the true speed of the processor. You may want to exercise     *)
  106.  (* your imagination there...                                     *)
  107.  (*                                                               *)
  108.  (* A word of caution, though. If you want a greater resolution,  *)
  109.  (* you will find preferable a routine that executes quickly.     *)
  110.  (* For example, I get a result of about 2300 on a 40mhz 80386DX  *)
  111.  (* and running under Windows. Your mileage may vary...           *)
  112.  (*****************************************************************)
  113.  procedure Representative_computations;
  114.  const Biggy_Size=2048;
  115.  type biggy= array[1..Biggy_size] of byte;
  116.  var b1, b2: ^biggy; {b1 and b2 are pointers to the big array.}
  117.  begin
  118.  new(b1);            {here, we allocate memory for the big arrays}
  119.  new(b2);
  120.  if random(10)>5
  121.     then b2^:=b1^    {here, we move the DATA from one big array to}
  122.     else b1^:=b2^;   {the other instead of only the pointer reference}
  123.  dispose(b2);        {and we nicely clean-up after ourselves,}
  124.  dispose(b1);        {by nicely giving-up the memory we used.}
  125.  end; {Representative_computations}
  126.  
  127.  (*****************************************************************)
  128.  (* This is the unit's initialization, where the computation for  *)
  129.  (* determining the system speed is done.                         *)
  130.  (*****************************************************************)
  131.  var timer: longint;
  132.  begin
  133.  timer:=Time_of_day;
  134.  repeat
  135.  until timer<>Time_of_day;
  136.  Timer:=Time_of_day;
  137.  TimeCount:=0;
  138.  repeat
  139.   inc(TimeCount);
  140.   Representative_computations;
  141.  until Timer<>Time_of_day;
  142.  end.
  143.  
  144.  (******************************************************)
  145.  (* Now, here is the main program that uses the stuff. *)
  146.  (******************************************************)
  147.  program test_time;
  148.  uses time;
  149.  begin
  150.  writeln('Machine speed=',time.speed_index);
  151.  end. ñ
  152.  
  153.  
  154.  
  155.